
## make 时不传参 PLAT 时使用下面配置
PLAT ?= x64

ROOT = $(shell pwd)
INSTALL_PATH = $(ROOT)/../install_$(PLAT)
WEBRTC_SRC = $(ROOT)/../src

include $(ROOT)/../platform/$(PLAT).mk

## 找不到 plat.mk 文件时的默认配置
PLAT_CPU ?= x64
GCC ?= gcc
GXX ?= g++
AR ?= ar

BUILD_WITH_NEON ?= 0

##### ----- 平台相关宏定义 ----- #####

## 平台相关
DEFINES += -DWEBRTC_LINUX
DEFINES += -DWEBRTC_POSIX
ifeq ($(PLAT_CPU),x64)
DEFINES += -D__x86_64__
else ifeq ($(PLAT_CPU),arm)
DEFINES += -D__ARMEL__
else ifeq ($(PLAT_CPU),arm64)
DEFINES += -D__aarch64__
endif

## 配置相关
DEFINES += -DWEBRTC_NON_STATIC_TRACE_EVENT_HANDLERS=0
DEFINES += -DWEBRTC_APM_DEBUG_DUMP=0
# DEFINES += -DWEBRTC_CHROMIUM_BUILD


##### ----- include & library & cflags ----- #####

TEST_INCS += $(EXT_INCS)
# TEST_INCS += -I$(WEBRTC_SRC)
# TEST_INCS += -I$(WEBRTC_SRC)/third_party/abseil-cpp
TEST_INCS += -I$(INSTALL_PATH)/include
TEST_INCS += -I$(INSTALL_PATH)/include/third_party
TEST_INCS += -I$(INSTALL_PATH)/include/third_party/abseil-cpp

TEST_LIBS += $(EXT_LIBS)
TEST_LIBS += -L$(INSTALL_PATH)/lib

TEST_CFLAGS += $(EXT_CFLAGS)
## 启用 neon
ifeq ($(BUILD_WITH_NEON),1)
ifneq ($(PLAT_CPU),arm64)
TEST_CFLAGS += -mfpu=neon
endif
endif
TEST_CFLAGS += -Wall


##### ----- base ----- #####

default_target += ns_test
default_target += legacy_agc_test
default_target += vad_test
default_target += aecm_test
ifeq ($(PLAT_CPU), x64)
default_target += agc_test
default_target += aec3
endif

all: $(default_target)

clean:
	@rm -rf $(ROOT)/*.out


##### ----- 模块测试 ----- #####

aec3_test:
	$(GXX) -o $(ROOT)/$@.out $(ROOT)/$@.cpp \
	$(TEST_INCS) $(TEST_LIBS) $(TEST_CFLAGS) $(DEFINES) \
	-l:libwebrtc_aec3.a -lpthread -std=c++17 -mavx2 -mfma

aecm_test:
	$(GXX) -o $(ROOT)/$@.out $(ROOT)/$@.cpp \
	$(TEST_INCS) $(TEST_LIBS) $(TEST_CFLAGS) $(DEFINES) \
	-l:libwebrtc_aecm.a

agc_test:
	$(GXX) -o $(ROOT)/$@.out $(ROOT)/$@.cpp \
	$(TEST_INCS) $(TEST_LIBS) $(TEST_CFLAGS) $(DEFINES) \
	-l:libwebrtc_agc.a -lpthread -std=c++17

legacy_agc_test:
	$(GXX) -o $(ROOT)/$@.out $(ROOT)/$@.cpp \
	$(TEST_INCS) $(TEST_LIBS) $(TEST_CFLAGS) $(DEFINES) \
	-l:libwebrtc_legacy_agc.a

vad_test:
	$(GXX) -o $(ROOT)/$@.out $(ROOT)/$@.cpp \
	$(TEST_INCS) $(TEST_LIBS) $(TEST_CFLAGS) $(DEFINES) \
	-l:libwebrtc_vad.a

ns_test:
	$(GXX) -o $(ROOT)/$@.out $(ROOT)/$@.cpp \
	$(TEST_INCS) $(TEST_LIBS) $(TEST_CFLAGS) $(DEFINES) \
	-l:libwebrtc_ns.a
